#include <QtGui>
#include <QTranslator>
#include <QtCore/QTextCodec>
#include "gv_systemtransmittershomedialog.h"
#include "gv_systemtransmittersconfigurationdialog.h"
#include "gv_systemhomedialog.h"
#include "gv_home.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_SystemTransmittersHomeDialog::GV_SystemTransmittersHomeDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(BackButton,SIGNAL(clicked()),this,SLOT(home()));
    connect(CancelButton,SIGNAL(clicked()),this,SLOT(home()));

    connect(pushButton_1,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(pushButton_2,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(pushButton_3,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(pushButton_4,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(pushButton_5,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(pushButton_6,SIGNAL(clicked()),this,SLOT(transmitterssetup()));

    connect(AllCOButton,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(AllLPGButton,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    connect(AllNOButton,SIGNAL(clicked()),this,SLOT(transmitterssetup()));
    AllCOButton->setText("CO Group");
    AllLPGButton->setText("LPG Group");
    AllNOButton->setText("NO Group");


    pushButton_1->setText("CO1");
    pushButton_2->setText("CO2");
    pushButton_3->setText("LPG1");
    pushButton_4->setText("LPG2");
    pushButton_5->setText("NO1");
    pushButton_6->setText("NO2");
    groupnum = 1;

    connect(UpButton,SIGNAL(clicked()),this,SLOT(transmittersup()));
    connect(DownButton,SIGNAL(clicked()),this,SLOT(transmittersdown()));
    timer->start(1000);
}

void GV_SystemTransmittersHomeDialog::transmittersup()
{
    if(groupnum > 1 && groupnum < 10)
    {
        groupnum--;
        pushButton_1->setText("CO"+QString::number(groupnum*2-1));
        pushButton_2->setText("CO"+QString::number(groupnum*2));
        pushButton_3->setText("LPG"+QString::number(groupnum*2-1));
        pushButton_4->setText("LPG"+QString::number(groupnum*2));
        pushButton_5->setText("NO"+QString::number(groupnum*2-1));
        pushButton_6->setText("NO"+QString::number(groupnum*2));

    }
}
void GV_SystemTransmittersHomeDialog::transmittersdown()
{
    if(groupnum > 0 && groupnum <9)
    {
        groupnum++;
        pushButton_1->setText("CO"+QString::number(groupnum*2-1));
        pushButton_2->setText("CO"+QString::number(groupnum*2));
        pushButton_3->setText("LPG"+QString::number(groupnum*2-1));
        pushButton_4->setText("LPG"+QString::number(groupnum*2));
        pushButton_5->setText("NO"+QString::number(groupnum*2-1));
        pushButton_6->setText("NO"+QString::number(groupnum*2));
    }
}
void GV_SystemTransmittersHomeDialog::reloadtext()
{
    //NameHintsLabel->setText(tr("Zones"));
}
void GV_SystemTransmittersHomeDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void GV_SystemTransmittersHomeDialog::home()
{
    QDialog *dialog1 = new GV_SystemHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SystemTransmittersHomeDialog::transmitterssetup()
{
    QDialog *dialog1 = new GV_SystemTransmittersConfigurationDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}



